package com.ruoyi.web.controller.lucky;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lucky.domain.TBoxsellInfo;
import com.ruoyi.lucky.service.ITBoxsellInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 盲盒出售Controller
 * 
 * @author ruoyi
 * @date 2020-11-12
 */
@Controller
@RequestMapping("/lucky/info")
public class TBoxsellInfoController extends BaseController
{
    private String prefix = "lucky/info";

    @Autowired
    private ITBoxsellInfoService tBoxsellInfoService;

    @RequiresPermissions("lucky:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询盲盒出售列表
     */
    @RequiresPermissions("lucky:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TBoxsellInfo tBoxsellInfo)
    {
        startPage();
        List<TBoxsellInfo> list = tBoxsellInfoService.selectTBoxsellInfoList(tBoxsellInfo);
        return getDataTable(list);
    }

    /**
     * 导出盲盒出售列表
     */
    @RequiresPermissions("lucky:info:export")
    @Log(title = "盲盒出售", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TBoxsellInfo tBoxsellInfo)
    {
        List<TBoxsellInfo> list = tBoxsellInfoService.selectTBoxsellInfoList(tBoxsellInfo);
        ExcelUtil<TBoxsellInfo> util = new ExcelUtil<TBoxsellInfo>(TBoxsellInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 新增盲盒出售
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存盲盒出售
     */
    @RequiresPermissions("lucky:info:add")
    @Log(title = "盲盒出售", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TBoxsellInfo tBoxsellInfo)
    {
        return toAjax(tBoxsellInfoService.insertTBoxsellInfo(tBoxsellInfo));
    }

    /**
     * 修改盲盒出售
     */
    @GetMapping("/edit/{boxsellId}")
    public String edit(@PathVariable("boxsellId") Long boxsellId, ModelMap mmap)
    {
        TBoxsellInfo tBoxsellInfo = tBoxsellInfoService.selectTBoxsellInfoById(boxsellId);
        mmap.put("tBoxsellInfo", tBoxsellInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存盲盒出售
     */
    @RequiresPermissions("lucky:info:edit")
    @Log(title = "盲盒出售", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TBoxsellInfo tBoxsellInfo)
    {
        return toAjax(tBoxsellInfoService.updateTBoxsellInfo(tBoxsellInfo));
    }

    /**
     * 删除盲盒出售
     */
    @RequiresPermissions("lucky:info:remove")
    @Log(title = "盲盒出售", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tBoxsellInfoService.deleteTBoxsellInfoByIds(ids));
    }
}
